package com.tz.colawallet.ui.presenter;

import com.tz.colawallet.basecode.base.BaseBiz;
import com.tz.colawallet.basecode.base.BaseRespNew;
import com.tz.colawallet.ui.biz.RegisterBiz;
import com.tz.colawallet.ui.contract.RegisterContract;

import javax.inject.Inject;

/**
 * Created by Administrator on 2017/10/25.
 */

public class RegisterPresenter implements RegisterContract.RegisterPresenter {

    RegisterContract.View view;
    RegisterBiz biz;

    @Inject
    public RegisterPresenter(RegisterContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        this.biz = (RegisterBiz) biz;
    }


    @Override
    public void sendSms(String phone) {
        view.loading(true);
        biz.sendSms(view.curContext(), phone, new BaseBiz.Callback<BaseRespNew>() {
            @Override
            public void onSuccess(BaseRespNew o) {
                view.sendSmsSuccess();
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }

    @Override
    public void register(String tel, String password, String code) {
        view.loading(true);
        biz.register(view.curContext(), tel, password, code, new BaseBiz.Callback<BaseRespNew>() {
            @Override
            public void onSuccess(BaseRespNew o) {
                view.registerSuccess();
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }

    @Override
    public void forget(String tel, String password, String code) {
        view.loading(true);
        biz.forget(view.curContext(), tel, password, code, new BaseBiz.Callback<BaseRespNew>() {
            @Override
            public void onSuccess(BaseRespNew o) {
                view.registerSuccess();
                view.loading(false);
            }

            @Override
            public void onFailure(BaseRespNew o) {
                view.showMsg(o.getMsg());
                view.loading(false);
            }
        });
    }

}
